package org.myorg.v5;


import java.io.Serializable;

public abstract class Gene5 implements Serializable {
/**
	 * 
	 */
	
	private static final long serialVersionUID = 111L;
	
	protected boolean DEBUG = false;

	//protected boolean DEBUG = true;
	
	public int length;
	public double goals[];
	public double crowd = 0;
	public int rank = 0;
	public int gene_type;
	
	public int ID = 0; 
	
	public Gene5(int length, int goals_num) {
		this.length = length;
		this.goals = new double[goals_num];		
	}
	
	/*
	 * gene_type: 0, float; 1, binary; others(such as 8) integer;
	 */
	public Gene5(int length, int goals_num, int gene_type) {
		this.length = length;
		this.goals = new double[goals_num];		
		this.gene_type = gene_type;
	}
	public Gene5(Gene5 gene) {
		this.length = gene.length;
		this.goals = gene.goals;		
		this.gene_type = gene.gene_type;
		this.crowd = gene.crowd;
		this.rank = gene.rank;
		this.ID = gene.ID;

	}
	public void print_goals() {
		if (DEBUG)
		for (int i = 0; i < goals.length; i++) {
			System.out.print(goals[i] + " ");
		}
	}
	public void print_crowd() {
		if (DEBUG)
		System.out.print(crowd + " ");
		
	}
	public void print_rank() {
		if (DEBUG)
		System.out.print(rank + " ");
		
	}
	public void print_ID() {
		if (DEBUG)
		System.out.print(ID + " ");
		
	}
	
	/*
	 * 1 p dominate q
	 *  0 p non-dominate q
	 *  -1 q dominate p
	 */
	public int dominate(FGene5 q) {
		int d = 0;
		int small = 0, equ = 0, big = 0;
		int gl = goals.length;
		
		for (int i = 0; i < gl; i++) {
			if (goals[i] == q.goals[i])
				equ++;
			else if (goals[i] < q.goals[i]) {
				small++;
			}else {
				big++;
			}
				
		}
		
		if (equ != gl ) {
			if (small + equ == gl) {
				d = 1;	
			} else if (small + equ == gl) {
				d = -1;
			}
			
		}
		return d;
	}
	
	public void set_ID(int id) {
		ID = id;
	}
}
